package view;

import java.util.HashMap;

import javax.swing.table.AbstractTableModel;

public class CodeTable extends AbstractTableModel {
	private static final long serialVersionUID = 8098477352885657343L;

	private final String[] COLUMN_NAMES = { "#", "Label", "Code" };

	private final int LABEL_COLUMN = 1;
	private final int CODE_COLUMN = 2;

	private final int rowCount;

	private HashMap<Integer, String> labels = new HashMap<Integer, String>();
	private HashMap<Integer, String> code = new HashMap<Integer, String>();

	public CodeTable(int rows) {
		rowCount = rows;
	}

	public int getLabelColumn() {
		return LABEL_COLUMN;
	}

	public int getCodeColumn() {
		return CODE_COLUMN;
	}

	public String getColumnName(int col) {
		return COLUMN_NAMES[col];
	}

	public int getRowCount() {
		return rowCount;
	}

	public int getColumnCount() {
		return COLUMN_NAMES.length;
	}

	public Object getValueAt(int row, int col) {
		if (col == LABEL_COLUMN) {
			return labels.get(row);
		} else if (col == CODE_COLUMN) {
			return code.get(row);
		} else {
			return new Integer(row);
		}
	}

	public boolean isCellEditable(int row, int col) {
		if (col != LABEL_COLUMN && col != CODE_COLUMN) {
			return false;
		}
		return true;
	}

	public void setValueAt(Object value, int row, int col) {
		if (col == LABEL_COLUMN) {
			labels.put(row, String.valueOf(value));
		}
		if (col == CODE_COLUMN) {
			code.put(row, String.valueOf(value));
		}
	}
}
